#pragma once

#ifndef _ACTOR_CLIENT_H_
#define _ACTOR_CLIENT_H_

#include <memory>
#include <functional>
#include "TcpClient.h"
#include "as_address.h"
#include "mailpos.h"
#include "as_callback.h"

class ByteBuffer;
typedef std::shared_ptr<ByteBuffer> ByteBufferPtr;


namespace as
{
namespace net
{
class EpollWatch;

class TcpConnection;
typedef std::shared_ptr<TcpConnection> TcpConnectionPtr;
}

namespace md
{

class ActorPacket;
class ActorClient : public as::net::TcpClient
{
public:
	typedef std::shared_ptr<ActorClient> ActorClientPtr;
	typedef std::function<void(int, ActorClient*)> RegisterActorFun;
	ActorClient(as::net::EpollWatch *ep, as::net::Address &serverAddr, const char *name, int pri_key = 0);
	virtual ~ActorClient();

	void HandleConnMsg(as::net::TcpConnectionPtr &con, ByteBufferPtr &buf, int size);

	void SetRegisterActorCallback(RegisterActorFun fun);
	void RunTimer();
	void SendMsg(ActorPacket *packet);
private:
	const int pri_key_ = 0;
	as::net::MsgCallback msg_cb_fun_;
	RegisterActorFun reg_actor_fun_;
	std::time_t heart_time_ = 0;
	int remote_id_ = 0;
};















	}
}

#endif